package com.inventory.repository;

import com.inventory.model.PurchaseRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface PurchaseRecordRepository extends JpaRepository<PurchaseRecord, Long> {
    
    List<PurchaseRecord> findByProductId(Long productId);
    
    List<PurchaseRecord> findByPurchaseDateBetween(LocalDateTime start, LocalDateTime end);
    
    @Query("SELECT SUM(pr.totalAmount) FROM PurchaseRecord pr WHERE pr.purchaseDate BETWEEN ?1 AND ?2")
    Double getTotalPurchaseAmountBetween(LocalDateTime start, LocalDateTime end);
    
    @Query("SELECT pr FROM PurchaseRecord pr WHERE pr.product.id = ?1 ORDER BY pr.purchaseDate DESC")
    List<PurchaseRecord> findLatestPurchasesByProductId(Long productId);
} 